package babo.cd.physicalexperiment.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.aliyun.player.AliPlayer;
import com.aliyun.player.AliPlayerFactory;
import com.aliyun.player.IPlayer;
import com.aliyun.player.bean.ErrorInfo;
import com.aliyun.player.nativeclass.PlayerConfig;
import com.aliyun.player.source.UrlSource;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cicada.player.utils.Logger;
import com.lxj.xpopup.XPopup;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import babo.cd.physicalexperiment.BaseActivity;
import babo.cd.physicalexperiment.R;
import babo.cd.physicalexperiment.bean.LinshiDatazyltBean;
import babo.cd.physicalexperiment.bean.ShiyanCommitBean;
import babo.cd.physicalexperiment.bean.ShiyanCommitZyltBean;
import babo.cd.physicalexperiment.bean.StartShiyanMqttBean;
import babo.cd.physicalexperiment.data.MyEnventData;
import babo.cd.physicalexperiment.data.RecordData;
import babo.cd.physicalexperiment.data.RecordZyltData;
import babo.cd.physicalexperiment.data.UserInfo;
import babo.cd.physicalexperiment.databinding.ActivityZiyouluotiBinding;
import babo.cd.physicalexperiment.dialog.AddHistoryDialog;
import babo.cd.physicalexperiment.dialog.AddHistoryZyltDialog;
import babo.cd.physicalexperiment.dialog.DialogCommon;
import babo.cd.physicalexperiment.dialog.TiaozhengzyltDialog;
import babo.cd.physicalexperiment.utils.OKCallback;
import babo.cd.physicalexperiment.utils.OkUtils;
import babo.cd.physicalexperiment.utils.Out;
import babo.cd.physicalexperiment.utils.SimpleUtils;
import babo.cd.physicalexperiment.utils.Tool;
import babo.cd.physicalexperiment.utils.URLS;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

import static babo.cd.physicalexperiment.activity.ImagePagerActivity.EXTRA_IMAGE_INDEX;
import static babo.cd.physicalexperiment.activity.ImagePagerActivity.EXTRA_IMAGE_URLS;

public class ZIyouluotiAcivity extends BaseActivity {
    ActivityZiyouluotiBinding binding;
        AliPlayer aliPlayer;
    CountDownTimer countDownTimer;
//    Surface surfaceView;
    AddHistoryZyltDialog addHistoryDialog;
    List<RecordZyltData> datas=new ArrayList<>();
    BaseQuickAdapter adapter;
    DialogCommon dialogCommon;
    private String deviceId="";
    private String did2="";
    private String playerUrl="";
    private String apid="";
    TiaozhengzyltDialog tiaozhengzyltDialog;
    Bitmap bitmapzhongdian;
    Bitmap bitmapqidian;
    private String currentLarurl="";
    private String currentSmall="";
    private String ctz0="0";
    private String wtz0="0";
    private String ctz1="0";
    private String didfq="";
    private String wtz1="0";
    ShiyanCommitZyltBean commitBean;
    private int flagstart=0;
    File fileStar;
    File fileMiddle;
    int flagzctc=0;
    Timer timer;
    private String pushUrl="";
    LinshiDatazyltBean linshiDatazyltBean;
    private String uid="";
    private TimerTask task;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
             doLoop();
            super.handleMessage(msg);
        }

    };

    private void doLoop() {
        OkUtils.GetOk(URLS.doLoop+"?deviceId="+deviceId,new OKCallback(context){
            @Override
            public void Sucess(String str) {
                super.Sucess(str);
                Out.out("轮询一次："+str);
            }

        });
    }

    @Override
    protected View bindView() {
        binding=ActivityZiyouluotiBinding.inflate(getLayoutInflater());
        return binding.getRoot();

    }

    @Override
    protected void onResume() {
        super.onResume();
        getUserInfo();
    }

    private void getUserInfo() {
        OkUtils.GetOk(URLS.getUserInfo,new OKCallback(context){
            @Override
            public void Eorror(int code) {
                super.Eorror(code);
                if (code==401){

                    doFq(1);

                }
            }

            @Override
            public void Sucess(String str) {
                super.Sucess(str);
                Out.out("用户信息："+str);

            }

        });
    }

    @Override
    protected void initView() {
        binding.rcv.setLayoutManager(new LinearLayoutManager(context));
        adapter=new BaseQuickAdapter(R.layout.item_shiyanzyltdata,datas) {
            @Override
            protected void convert(BaseViewHolder helper, Object item) {
                bindConvert(helper,(RecordZyltData)item);
            }

        };
        binding.rcv.setAdapter(adapter);
//        binding.svPlay.setWebViewClient(new ExampleWebViewClient());
//        binding.svPlay.getSettings().setJavaScriptEnabled(true);
//        binding.svPlay.getSettings().setMediaPlaybackRequiresUserGesture(false);
//        binding.svPlay.getSettings().setLoadWithOverviewMode(true);
//        binding.svPlay.getSettings().setUseWideViewPort(true);
//
//        binding.svPlay.getSettings().setPluginState(WebSettings.PluginState.ON);
//        binding.svPlay.getSettings().setAllowFileAccess(true);
//        binding.svPlay.getSettings().setSupportZoom(true);
//        binding.svPlay.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//
//        if (Build.VERSION.SDK_INT >= 21) {
//            binding.svPlay.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
//        }

//        wb.setWebChromeClient(wvcc);


    }
    private class ExampleWebViewClient extends WebViewClient {
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onLoadResource(WebView view, String url) {
            super.onLoadResource(view, url);
        }
    }
    private void bindConvert(BaseViewHolder helper, RecordZyltData item) {
        TextView txcutiao=helper.getView(R.id.txcutiao);
        TextView txweitiao=helper.getView(R.id.txweitiao);
        TextView txjsz=helper.getView(R.id.txjsz);
        TextView tx_caozuo=helper.getView(R.id.tx_caozuo);
        TextView txxuhao=helper.getView(R.id.txxuhao);
        txcutiao.setText(item.getStartValue());
        txweitiao.setText(item.getMiddleValue());
        txjsz.setText(item.getTimeDifference());
        int positon=helper.getAdapterPosition();
        txxuhao.setText((positon+1)+"");

        datas.get(positon).setOrderNo((positon+1)+"");
       Out.out("bind数据");
        tx_caozuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doDelete(positon);
            }
        });
    }

    private void doDelete(int adapterPosition) {
        dialogCommon=new DialogCommon(context);
        dialogCommon.setTitle("提示");
        dialogCommon.setMessage("确定删除该记录吗？");
        dialogCommon.setConfirm("确定", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCommon.dismiss();
                datas.remove(adapterPosition);
                linshiDatazyltBean.setDds(datas);
                String js=gson.toJson(linshiDatazyltBean);
                SharedPreferences.Editor ed=sharedPreferences.edit();
                ed.putString("zyltdata"+uid,js);
                ed.commit();


                adapter.notifyDataSetChanged();
                if (datas.size()==0){
                    binding.lltt.setVisibility(View.GONE);
                    binding.txZwjl.setVisibility(View.VISIBLE);
                }
            }
        });
        dialogCommon.setCancel("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCommon.dismiss();
            }
        });
        dialogCommon.show();

    }

    @Override
    protected void loadData() {
        playerUrl=getIntent().getStringExtra("purl");
        pushUrl=getIntent().getStringExtra("pushurl");
        did2=getIntent().getStringExtra("did");
        didfq=getIntent().getStringExtra("didfq");
//        deviceId="807d3ab6fbf0-ZYLT-0001";
        linshiDatazyltBean=new LinshiDatazyltBean();

        uid=sharedPreferences.getString("uid","");


        String datajson=sharedPreferences.getString("zyltdata"+uid,"");
        if (!TextUtils.isEmpty(datajson)){
         try {
             LinshiDatazyltBean linshiDatazyltBean=gson.fromJson(datajson,LinshiDatazyltBean.class);
             datas.addAll(linshiDatazyltBean.getDds());
             adapter.notifyDataSetChanged();

         }catch (Exception exception){}

        }
        aliPlayer= AliPlayerFactory.createAliPlayer(this);
        PlayerConfig config = aliPlayer.getConfig();
//设置最大延迟为1秒，延迟控制由ARTC控制
        config.mMaxDelayTime = 1000;
//设置播放器启播缓存为10毫秒，数据控制由ARTC控制。
        config.mHighBufferDuration = 10;
        config.mStartBufferDuration = 10;
//其他设置
//给播放器加载配置
        aliPlayer.setConfig(config);

        deviceId=did2;
        apid=getIntent().getStringExtra("apid");
        commitBean=new ShiyanCommitZyltBean();
        System.loadLibrary("RtsSDK");
        countDownTimer= new CountDownTimer(30*60*1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                String value = String.valueOf((int) (millisUntilFinished / 1000));
                int syms=(int) (millisUntilFinished / 1000);
                Out.out("syms=="+syms);

                int fz= syms/60;
                int mz=syms%60;

                String sfz="";
                String smz="";
                if (fz<10){
                    sfz="0"+fz;
                }else{
                    sfz=fz+"";
                }
                if (mz<10){
                    smz="0"+mz;
                }else{
                    smz=mz+"";
                }
                binding.txTimedjs.setText("实验剩余时间: "+sfz+":"+smz);

//                mTvValue.setText(value);
            }

            @Override
            public void onFinish() {

                Out.toast(context,"实验时间已到！");
                finish();
            }
        };
        countDownTimer.start();

        EventBus.getDefault().post(MyEnventData.getInstance("startshiyanzylt@"+deviceId+"@"+pushUrl));


     timer=new Timer();
        task = new TimerTask() {
            @Override
            public void run() {
                Message message = new Message();
                message.what = 1;
                handler.sendMessage(message);
            }
        };
        timer.schedule(task, 1000, 30000);





    }

    private void doInitLivePlay() {
        Out.out("开始拉流AAA");

        Logger.getInstance(context).enableConsoleLog(true);
        Logger.getInstance(context).setLogLevel(Logger.LogLevel.AF_LOG_LEVEL_TRACE);
//        EventBus.getDefault().post(MyEnventData.getInstance("startshiyanmkex@"+deviceId));

        SurfaceView surfaceView=new SurfaceView(context);
        binding.svPlay.addView(surfaceView);
        SurfaceHolder holder=  surfaceView.getHolder();


        //得到视图的状态
        holder.addCallback(new SurfaceHolder.Callback() {
            //视图销毁
            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {
                // TODO Auto-generated method stub
                aliPlayer.setDisplay(holder);
            }
            //视图创建完成
            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                // TODO Auto-generated method stub
                Out.out("准备好AAA1");
                aliPlayer.setDisplay(holder);
                aliPlayer.setSurface(holder.getSurface());
                aliPlayer.setOnErrorListener(new IPlayer.OnErrorListener() {
                    @Override
                    public void onError(ErrorInfo errorInfo) {
                        //出错事件
                        Out.out("错粗：="+errorInfo.getMsg());
                        Out.out("错粗22：="+errorInfo.getExtra());
                    }
                });
//        long duration = androidMediaPlayer.getDuration();
                try {
                    String path="artc://xhapp.cdbfbt.cn/555/555?auth_key=1623554479-0-0-1c73cef9d3744a0db57e143a74151f26";


                    path=playerUrl;
                    Out.out("推流地址=="+path);
//                    path="http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8";

                    UrlSource urlSource=new UrlSource();
                    urlSource.setUri(path);
                    //设置资源
                    aliPlayer.setDataSource(urlSource);
                    //异步准备
                    aliPlayer.prepare();
                    //播放
                    aliPlayer.setOnPreparedListener(new IPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared() {
                            Out.out("视频准备好");
                            aliPlayer.start();
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    Out.out("推流错误=="+e.getMessage());
                }

            }
            //视图改变
            @Override
            public void surfaceChanged(SurfaceHolder holder, int format, int width,
                                       int height) {
                aliPlayer.redraw();

            }
        });



    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        try {
            aliPlayer.stop();
            aliPlayer.release();;
        }catch (Exception e){}

        try {
            countDownTimer.cancel();
        }catch (Exception ex){}
        try {
            if (flagzctc==0){
                Out.out("不正常退出QQQ");
                EventBus.getDefault().post(MyEnventData.getInstance("giveupshiyanzyltdd@"+deviceId));
            }

        }catch (Exception ex){}


        try {
            timer.cancel();
            timer=null;
        }catch (Exception ex){}
        try {
            task.cancel();
            task=null;
        }catch (Exception ex){}

    }

    @Override
    public void leftClick() {
        super.leftClick();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {


        if (keyCode==KeyEvent.KEYCODE_BACK){
            doFagnqi();
        }
        if (keyCode==KeyEvent.KEYCODE_HOME){
            doFagnqi();
        }
        return  true;
    }



    @Override
    public void setListener() {
        super.setListener();
        binding.ivQidian.setOnClickListener(v -> {

         File fqd= SimpleUtils.save2Album2(context, bitmapqidian);
            String [] urls={fqd.getAbsolutePath()};
            Out.out("起点图片=="+fqd.getAbsolutePath());

            Intent intent=new Intent(context,ImagePagerActivity.class);
            intent.putExtra(EXTRA_IMAGE_INDEX,0);
            intent.putExtra(EXTRA_IMAGE_URLS,urls);
            startActivity(intent);
        });
        binding.ivZhongdian.setOnClickListener(v -> {
            if (bitmapzhongdian==null){
                return;
            }
            File fqd= SimpleUtils.save2Album2(context, bitmapzhongdian);
            String [] urls={fqd.getAbsolutePath()};
            Out.out("中点图片=="+fqd.getAbsolutePath());

            Intent intent=new Intent(context,ImagePagerActivity.class);
            intent.putExtra(EXTRA_IMAGE_INDEX,0);
            intent.putExtra(EXTRA_IMAGE_URLS,urls);
            startActivity(intent);
        });
        binding.txFangqi.setOnClickListener(v -> {
            doFagnqi();
        });
        binding.txSubmit.setOnClickListener(v -> {
            doComit();
        });

        binding.topbar.getIm_back().setOnClickListener(v -> {
            doFagnqi();
        });
        binding.txbtantzjd.setOnClickListener(view -> {
            tiaozhengzyltDialog=new TiaozhengzyltDialog(deviceId,this,currentLarurl,currentSmall,ctz0,ctz1,wtz0,wtz1);
            new XPopup.Builder(context)
                    .dismissOnTouchOutside(false)
                    .asCustom(tiaozhengzyltDialog)
                    .show();
            if (bitmapzhongdian!=null)
            hd.postDelayed(new Runnable() {
                @Override
                public void run() {
                    tiaozhengzyltDialog.setZhongidan(bitmapzhongdian);
                    tiaozhengzyltDialog.setQidian(bitmapqidian);
                }
            },300);
        });
        binding.txYxstart.setOnClickListener(view -> {
            if (flagstart==0){
                flagstart=1;

                StartShiyanMqttBean startShiyanMqttBean =new StartShiyanMqttBean();
                startShiyanMqttBean.setAction("begin");
                startShiyanMqttBean.setDevice_id(deviceId);
                startShiyanMqttBean.setExp_id("2");
                EventBus.getDefault().post(MyEnventData.getInstance("begin@"+gson.toJson(startShiyanMqttBean)));
                binding.txYxstart.setText("实验中");
                binding.txYxstart.setBackgroundResource(R.drawable.backbtnhuise);
                binding.txYxsc.setText("实验时长:--");
            }else{

            }
        });

    }

    private void doComit() {
        dialogCommon=new DialogCommon(context);
        dialogCommon.setTitle("提示");
        dialogCommon.setMessage("本次实验共添加"+datas.size()+"条数据记录，确认要完成实验吗？");
        dialogCommon.setConfirm("确定", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCommon.dismiss();
                doCommit();
            }
        });
        dialogCommon.setCancel("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCommon.dismiss();
            }
        });
        dialogCommon.show();
    }

    private void doFagnqi() {
        dialogCommon=new DialogCommon(context);
        dialogCommon.setTitle("提示");
        dialogCommon.setMessage("实验未完成，确定要放弃本次实验？");
        dialogCommon.setConfirm("确定", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCommon.dismiss();
                doFq(0);
            }
        });
        dialogCommon.setCancel("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCommon.dismiss();
            }
        });
        dialogCommon.show();
    }
    private void doCommit() {
        commitBean.setAppointmentId(apid);
        commitBean.setDeviceId(didfq);
        commitBean.setResult("1");
        commitBean.setRecords(datas);

        String jsondata=gson.toJson(commitBean);
        LinkedHashMap map=new LinkedHashMap();
        map.put("data",jsondata);
        OkUtils.performByJson23(context, URLS.commitshiyanzylt,jsondata,2,new OKCallback(context){
            @Override
            public void Sucess(String str) {
                super.Sucess(str);
                flagzctc=1;
                Out.toast(context,"提交成功！");
                SharedPreferences.Editor ed=sharedPreferences.edit();
                ed.putString("zyltdata"+uid,"");
                ed.commit();
                EventBus.getDefault().post(MyEnventData.getInstance("endshiyanzylt@"+deviceId));
                setResult(81);
                finish();
            }
        });

    }

    private void doFq(int flag) {

        commitBean.setAppointmentId(apid);
        commitBean.setDeviceId(didfq);
        commitBean.setResult("2");
        commitBean.setRecords(datas);
        String jsondata=gson.toJson(commitBean);
        LinkedHashMap map=new LinkedHashMap();
        map.put("data",jsondata);
        OkUtils.performByJson23(context, URLS.commitshiyan,jsondata,2,new OKCallback(context){
            @Override
            public void Sucess(String str) {
                super.Sucess(str);
                flagzctc=1;
                EventBus.getDefault().post(MyEnventData.getInstance("giveupshiyanzylt@"+deviceId));
                SharedPreferences.Editor ed=sharedPreferences.edit();
                ed.putString("zyltdata"+uid,"");
                ed.commit();
                if (flag==0){
                    finish();
                }else{
                    UserInfo.userId="";
                    UserInfo.JsessionId="";
                    Out.toast(context,"用户超时，请重新登录！");
                    Intent intent=new Intent(context, LoginActivity.class);
                    startActivity(intent);
                    finish();


                }

            }
        });

    }

    private void doAddhistory() {

    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGetMessage(MyEnventData message) {
        String msg=message.message;
        if (msg.equals("noballerror")){
            Out.toastLong(context,"实验失败：回收小球超时，请重新开始实验！");

            binding.txYxsc.setText("实验时长:--");
            binding.txYxstart.setText("开始实验");
            flagstart=0;
            binding.txYxstart.setBackgroundResource(R.drawable.backbtngreen);

        }
        if (msg.equals("notimecose")){
            Out.toastLong(context,"实验失败：光电未检测到小球，请重新开始实验");
            binding.txYxsc.setText("实验时长:--");
            binding.txYxstart.setText("开始实验");
            flagstart=0;
            binding.txYxstart.setBackgroundResource(R.drawable.backbtngreen);
        }
        if (msg.equals("startpull")){
            doInitLivePlay();
        }
        if (msg.startsWith("shiyanfinish@")){
            msg=msg.replace("shiyanfinish@","");
            binding.txYxsc.setText("运行时长:"+msg+"s");
            binding.txYxstart.setText("开始实验");
            flagstart=0;
            binding.txYxstart.setBackgroundResource(R.drawable.backbtngreen);
            addHistoryDialog=new AddHistoryZyltDialog (this,msg,fileStar,fileMiddle);
            new XPopup.Builder(context)
                    .dismissOnTouchOutside(true)
                    .asCustom(addHistoryDialog)
                    .show();

        }
//        if (msg.startsWith("playvedio@")){
//            Out.out("处理视频");
//            msg=msg.replace("playvedio@","");
////            msg="https://www.baidu.com/";
//            binding.svPlay.loadUrl(msg);
//            Out.toast(context,"开始播放视频："+msg);
//
//        }
        if (msg.startsWith("showimg@")){
            msg=msg.replace("showimg@","");
            final  String mm=msg;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    hd.post(new Runnable() {
                        @Override
                        public void run() {
                            Bitmap bitmap= Tool.stringToBitmap(mm);

                            binding.ivZhongdian.setBackgroundResource(0);
                            try {
                                fileMiddle= SimpleUtils.save2Album2(context, bitmap);
                                binding.ivZhongdian.setImageURI(Uri.fromFile(fileMiddle));

                                bitmapzhongdian=bitmap;


                                try {
                                    if (tiaozhengzyltDialog.isShow()){
                                        tiaozhengzyltDialog.setZhongidan(bitmap);
                                    }
                                }catch (Exception ex){}
                            }catch (Exception ex){
                                ex.printStackTrace();
                            }

                        }
                    });

                }
            }).start();



        }
        if (msg.startsWith("showimgqd@")){
            msg=msg.replace("showimgqd@","");


            final  String mm=msg;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    hd.post(new Runnable() {
                        @Override
                        public void run() {

                            Bitmap bitmap= Tool.stringToBitmap(mm);
                            binding.ivQidian.setBackgroundResource(0);
                            try {
                                fileStar= SimpleUtils.save2Album2(context, bitmap);
                                binding.ivQidian.setImageURI(Uri.fromFile(fileStar));
                                bitmapqidian=bitmap;


                                try {
                                    if (tiaozhengzyltDialog.isShow()){
                                        tiaozhengzyltDialog.setQidian(bitmap);
                                    }
                                }catch (Exception ex){}
                            }catch (Exception ex){
                                ex.printStackTrace();
                            }





                        }
                    });

                }
            }).start();








        }
        if (msg.startsWith("tiaozhengmkex@")){
            msg=msg.replace("tiaozhengmkex@","");
            String[] ss=msg.split("@");//+cv0+"@"+wv0+"@"+cv1+"@"+wv1
            ctz0=ss[0];
            wtz0=ss[1];
            ctz1=ss[2];
            wtz1=ss[3];
            binding.txKedu.setText("起点粗调："+ctz1+"cm");
            binding.txKedu2.setText("起点微调："+wtz1+"mm");
            binding.txKedu3.setText("中点粗调："+ctz0+"cm");
            binding.txKedu4.setText("中点微调："+wtz0+"mm");
        }
        if (msg.startsWith("addhistoryzylt@")){
            msg=msg.replace("addhistoryzylt@","");
            RecordZyltData recordData=gson.fromJson(msg,RecordZyltData.class);
            datas.add(recordData);
            adapter.notifyDataSetChanged();

            binding.txZwjl.setVisibility(View.GONE);
            binding.lltt.setVisibility(View.VISIBLE);

            linshiDatazyltBean.setDds(datas);
            String js=gson.toJson(linshiDatazyltBean);
            SharedPreferences.Editor ed=sharedPreferences.edit();
            ed.putString("zyltdata"+uid,js);
            ed.commit();
        }

    }


    public static void post3(String address, okhttp3.Callback callback, Map<String, String> map, File mfile, File mfile2, File mfile3, String token) {

        address= URLS.HTTPHEAD+address;
        OkHttpClient client = new OkHttpClient();
        MultipartBody.Builder builder = new MultipartBody.Builder();
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                builder.addFormDataPart(entry.getKey(), entry.getValue());
            }
        }


        if (mfile != null) {


            String TYPE = "application/octet-stream";
            RequestBody fileBody = RequestBody.create(MediaType.parse(TYPE), mfile);
            RequestBody requestBody = builder
                    .setType(MultipartBody.FORM)
                    .addFormDataPart("image ", mfile.getName(), fileBody)
                    .build();
            Request request = new Request.Builder()
                    .url(address)
                    .post(requestBody)
                    .addHeader("Cookie", "JSESSIONID="+ UserInfo.JsessionId)
                    .build();
            client.newCall(request).enqueue(callback);
            Out.out("开始网络请求没111=="+address);

        } else {
//            Log.d(TAG, "post3: 文件不存在");
//            RequestBody requestBody = builder
//                    .setType(MultipartBody.FORM)
//                    .build();
//            Request request = new Request.Builder()
//                    .url(address)
//                    .post(requestBody)
//                    .addHeader("Cookie", "JSESSIONID="+ UserInfo.JsessionId)
//                    .build();
//            client.newCall(request).enqueue(callback);
            Out.out("开始网络请求没：000---"+address);
        }

    }

}
